﻿/*
 * @Autor: PK
 */

using System;
using System.Diagnostics;
using System.Threading.Tasks;
using ShkSimulation.core.util.osm;

namespace ShkSimulation.core.util.http {
	public class DownloadUtil {
		
		public static void ContinousDownloadFile(string url, string savePathFile) {
			Stopwatch stopwatch = new Stopwatch();
			stopwatch.Start();
			Task t = new Task(() => {
				var info1 = HttpUtilWrapper.GetRemoteLinkDownloadInfo(url);
				var downInfo1 = new RemoteLinkDownloadWithLinkInfo(info1, url);
				var downloader = new HttpStableDownloader(url, savePathFile, downInfo1.eTag, downInfo1.filesize);
				if (downInfo1.supportResumeDownload) {
					downloader.ResumeProgressDelegate = (progress, errorCode) => {
						Console.WriteLine("progress " + progress + " code " + errorCode);
					};
					downloader.ResumeDownload();//ResumeDownloadAsync();
				} else {
					downloader.NotResumeSizeChangeDelegate = (receivedKB, errorCode) => {
						Console.WriteLine("receivedKB " + receivedKB + " code " + errorCode);
					};
					downloader.NotResumeDownload();//NotResumeDownloadAsync();
				}
			});
			t.Start();
			t.Wait();
			stopwatch.Stop();
			Console.WriteLine(stopwatch.Elapsed);
		}
	}
}